package com.bupt.ilink.service.bailian.impl;

import com.aliyun.bailian20231229.models.CreateIndexResponse;
import com.aliyun.tea.TeaException;
import com.bupt.ilink.service.bailian.CreateIndexService;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class CreateIndexServiceImpl implements CreateIndexService {
/**
 * 返回格式，注意当sourceType为DATA_CENTER_FILE时，documentIds不能为空，且categoryIds值没用。反之同理
 * {
 *   "Status": 200,
 *   "RequestId": "D6180DB2-DF2F-9C0E-B843-BF3ED627E5D2",
 *   "Message": "success",
 *   "Data": {
 *     "Id": "0eni7abzcn"
 *   },
 *   "Code": "Success",
 *   "Success": true
 * }
 **/
    @Override
    public CreateIndexResponse createIndex(com.aliyun.bailian20231229.Client client, String workspaceId, String name, String structureType, String embeddingModelName,
                            String rerankModelName, double rerankMinScore, Integer chunkSize, Integer overlapSize,
                            String sourceType, List<String> documentIds, List<String> categoryIds, String sinkType, String description) throws Exception {
        com.aliyun.bailian20231229.models.CreateIndexRequest createIndexRequest = new com.aliyun.bailian20231229.models.CreateIndexRequest()
                .setName(name)
                .setStructureType(structureType)
                .setEmbeddingModelName(embeddingModelName)
                .setRerankModelName(rerankModelName)
                .setRerankMinScore(rerankMinScore)
                .setChunkSize(chunkSize)
                .setOverlapSize(overlapSize)
                .setSourceType(sourceType)
                .setDocumentIds(documentIds)
                .setCategoryIds(categoryIds)
                .setSinkType(sinkType)
                .setDescription(description);
        com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();
        java.util.Map<String, String> headers = new java.util.HashMap<>();
        try {
            // 复制代码运行请自行打印 API 的返回值
            return client.createIndexWithOptions(workspaceId, createIndexRequest, headers, runtime);
        } catch (TeaException error) {
            // 此处仅做打印展示，请谨慎对待异常处理，在工程项目中切勿直接忽略异常。
            // 错误 message
            System.out.println(error.getMessage());
            // 诊断地址
            System.out.println(error.getData().get("Recommend"));
            com.aliyun.teautil.Common.assertAsString(error.message);
            throw new TeaException(error.getMessage(), error);
        } catch (Exception _error) {
            TeaException error = new TeaException(_error.getMessage(), _error);
            // 此处仅做打印展示，请谨慎对待异常处理，在工程项目中切勿直接忽略异常。
            // 错误 message
            System.out.println(error.getMessage());
            // 诊断地址
            System.out.println(error.getData().get("Recommend"));
            com.aliyun.teautil.Common.assertAsString(error.message);
            throw new Exception(error.getMessage());
        }
    }

    @Override
    public CreateIndexResponse createIndex(com.aliyun.bailian20231229.Client client, String workspaceId, String name, String structureType, String sourceType, List<String> documentIds, List<String> categoryIds, String sinkType) throws Exception {
        com.aliyun.bailian20231229.models.CreateIndexRequest createIndexRequest = new com.aliyun.bailian20231229.models.CreateIndexRequest()
                .setName(name)
                .setStructureType(structureType)
                .setEmbeddingModelName("text-embedding-v2")
                .setRerankModelName("gte-rerank-hybrid")
                .setRerankMinScore(0.20)
                .setChunkSize(200)
                .setOverlapSize(50)
                .setSourceType(sourceType)
                .setDocumentIds(documentIds)
                .setCategoryIds(categoryIds)
                .setSinkType(sinkType);
        com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();
        java.util.Map<String, String> headers = new java.util.HashMap<>();
        try {
            // 复制代码运行请自行打印 API 的返回值
            return client.createIndexWithOptions(workspaceId, createIndexRequest, headers, runtime);
        } catch (TeaException error) {
            // 此处仅做打印展示，请谨慎对待异常处理，在工程项目中切勿直接忽略异常。
            // 错误 message
            System.out.println(error.getMessage());
            // 诊断地址
            System.out.println(error.getData().get("Recommend"));
            com.aliyun.teautil.Common.assertAsString(error.message);
            throw new TeaException(error.getMessage(), error);
        } catch (Exception _error) {
            TeaException error = new TeaException(_error.getMessage(), _error);
            // 此处仅做打印展示，请谨慎对待异常处理，在工程项目中切勿直接忽略异常。
            // 错误 message
            System.out.println(error.getMessage());
            // 诊断地址
            System.out.println(error.getData().get("Recommend"));
            com.aliyun.teautil.Common.assertAsString(error.message);
            throw new Exception(error.getMessage());
        }
    }

    @Override
    public CreateIndexResponse createIndexWithDoc(com.aliyun.bailian20231229.Client client, String workspaceId, String name, String structureType, List<String> documentIds, String sinkType) throws Exception {
        com.aliyun.bailian20231229.models.CreateIndexRequest createIndexRequest = new com.aliyun.bailian20231229.models.CreateIndexRequest()
                .setName(name)
                .setStructureType(structureType)
                .setEmbeddingModelName("text-embedding-v2")
                .setRerankModelName("gte-rerank-hybrid")
                .setRerankMinScore(0.20)
                .setChunkSize(200)
                .setOverlapSize(50)
                .setSourceType("DATA_CENTER_FILE")
                .setDocumentIds(documentIds)
                .setSinkType(sinkType);
        com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();
        java.util.Map<String, String> headers = new java.util.HashMap<>();
        try {
            // 复制代码运行请自行打印 API 的返回值
            return client.createIndexWithOptions(workspaceId, createIndexRequest, headers, runtime);
        } catch (TeaException error) {
            // 此处仅做打印展示，请谨慎对待异常处理，在工程项目中切勿直接忽略异常。
            // 错误 message
            System.out.println(error.getMessage());
            // 诊断地址
            System.out.println(error.getData().get("Recommend"));
            com.aliyun.teautil.Common.assertAsString(error.message);
            throw new TeaException(error.getMessage(), error);
        } catch (Exception _error) {
            TeaException error = new TeaException(_error.getMessage(), _error);
            // 此处仅做打印展示，请谨慎对待异常处理，在工程项目中切勿直接忽略异常。
            // 错误 message
            System.out.println(error.getMessage());
            // 诊断地址
            System.out.println(error.getData().get("Recommend"));
            com.aliyun.teautil.Common.assertAsString(error.message);
            throw new Exception(error.getMessage());
        }
    }

    @Override
    public CreateIndexResponse createIndexWithCat(com.aliyun.bailian20231229.Client client, String workspaceId, String name, String structureType, List<String> categoryIds, String sinkType) throws Exception {
        com.aliyun.bailian20231229.models.CreateIndexRequest createIndexRequest = new com.aliyun.bailian20231229.models.CreateIndexRequest()
                .setName(name)
                .setStructureType(structureType)
                .setEmbeddingModelName("text-embedding-v2")
                .setRerankModelName("gte-rerank-hybrid")
                .setRerankMinScore(0.20)
                .setChunkSize(200)
                .setOverlapSize(50)
                .setSourceType("DATA_CENTER_CATEGORY")
                .setCategoryIds(categoryIds)
                .setSinkType(sinkType);
        com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();
        java.util.Map<String, String> headers = new java.util.HashMap<>();
        try {
            // 复制代码运行请自行打印 API 的返回值
            return client.createIndexWithOptions(workspaceId, createIndexRequest, headers, runtime);
        } catch (TeaException error) {
            // 此处仅做打印展示，请谨慎对待异常处理，在工程项目中切勿直接忽略异常。
            // 错误 message
            System.out.println(error.getMessage());
            // 诊断地址
            System.out.println(error.getData().get("Recommend"));
            com.aliyun.teautil.Common.assertAsString(error.message);
            throw new TeaException(error.getMessage(), error);
        } catch (Exception _error) {
            TeaException error = new TeaException(_error.getMessage(), _error);
            // 此处仅做打印展示，请谨慎对待异常处理，在工程项目中切勿直接忽略异常。
            // 错误 message
            System.out.println(error.getMessage());
            // 诊断地址
            System.out.println(error.getData().get("Recommend"));
            com.aliyun.teautil.Common.assertAsString(error.message);
            throw new Exception(error.getMessage());
        }
    }
}
